package com.example.lib.listener

import android.view.View

abstract class OnDoubleClickListener : View.OnClickListener {

    private var lastClickTime: Long = 0

    override fun onClick(v: View) {
        if (!isFastDoubleClick())
            onDoubleClick(v)
    }

    protected abstract fun onDoubleClick(view: View?)

    private fun isFastDoubleClick(): Boolean {
        val time = System.currentTimeMillis()
        val timeD = time - lastClickTime
        if (timeD in 1..499) {
            return true
        }
        lastClickTime = time
        return false
    }
}